<template>
    <div>
        <home v-if="reg" ></home>
        <register v-if="!reg"></register>
    </div>
</template>

<script>
    import home  from '../goHome/Home.vue'
    import register  from '../goHome/Register.vue'
    import  {getAction} from '../api/manage'
    import Notify from "vant/lib/notify";
    export default {
        name: "auth",
        components: {
            home,
            register
        },
        data() {
            return {
                reg: false,
                err:''
                //reg: window.localStorage.getItem('reg')
            }
        },
        mounted() {
          // let openid = window.localStorage.getItem('openid')
           // 测试账号
            let openid ='oQtMMwkcwDP1Ex27WxOKcu933lbM'
           window.localStorage.setItem('openid',openid)
            if(openid)
            getAction('/getAuthorization',openid).then(res=>{
                console.log(res)
                this.reg=res.success;
                if(this.reg === false){
                    Notify({message:'用户未授权请先申请授权:',type:'warning',duration: 1500})
                }
                else{
                    window.localStorage.setItem('result',JSON.stringify(res.result))
                }
            }).catch(err=>{
                this.reg=false;
                this.err =err

              //  Notify({message:'服务连接超时:'+err,type:'danger',duration: 1500})
            })

        },
        destroyed() {
            window.localStorage.removeItem('openid')
            window.localStorage.clear();
            this.ws.close() //离开路由之后断开websocket连接
        }
    }
</script>

<style scoped>

</style>